#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <stack>
using namespace std;

int main() {
	int N;
	while (scanf("%d", &N) != EOF && N) {
		stack <int> s1, s3;
		int s2[15000];
		int d = 2, i, flag = 0;
		for (i = 1; i <= N; i++)
			scanf("%d", &s2[i]);
		for (i = N; i >= 1; i--)
			s1.push(s2[i]);
		s3.push(1);
		while (1) {
			if (s3.top() == s1.top()) {
				s1.pop();
				s3.pop();
			}
			if (s1.empty() && s3.empty()) {
				flag = 1;
				break;
			}

			if (s3.empty())
				s3.push(d++);
			else if (s3.top() != s1.top())
				s3.push(d++);
			if (d == N + 2)
				break;
		}
		if (flag)
			printf("Yes\n");
		else
			printf("No\n");
	}
}
